package com.cy.jwt.controller;

import com.cy.jwt.utils.JwtUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AuthController {
    @RequestMapping("/login")
    public Map<String, Object> doLogin(String username, String password) {
        HashMap<String, Object> map = new HashMap<>();
        if ("jack".equals(username) && "123456".equals(password)) {
            map.put("start", "200");
            map.put("message", "login ok");
            HashMap<String, Object> claims = new HashMap<>();
            claims.put("username", username);
            map.put("Authentication", JwtUtils.generateToken(claims));
            return map;
        } else {
            map.put("state", "500");
            map.put("message", "login failure");
            return map;
        }

    }
}
